#!/usr/bin/python

import imaplib
import poplib

def pop_auth(host, username, password, port, ssl):
	try:
		if ssl:
			pp = poplib.POP3_SSL(host, port)
		else:
			pp = poplib.POP3(host, port)
		pp.set_debuglevel(0)
		pp.user(username)
		s = pp.pass_(password)
		ret = pp.stat()
	except poplib.error_proto:
		print "check wrong!"
		pp.quit()
		return 0
	except socket.error:
		print "connection error"
		return -1
	print "check ok!"	
	pp.quit()
	return 1

def imap_auth(host, username, password, port, ssl):
	try:
		if ssl:
			imap = imaplib.IMAP4_SSL(host, port)
		else:
			imap = imaplib.IMAP4(host, port)
	except socket.error:
		print "connection error"
		return -1

	try:
		imap.login(username, password)
	except:
		print "check wrong!"
		imap.logout()
		return 0
	print "check ok!"	
	imap.logout()
	return 1

pop_auth('pop.qq.com', 'aa', 'asd,qq', 110, 0)
